package com.quick.im.client.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import org.springframework.web.socket.TextMessage;

@Slf4j
public class ChatWebSocketHandler extends TextWebSocketHandler {

    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        // 接收到的消息
        String incomingMessage = message.getPayload();
        log.info("Received message: " + incomingMessage);

        // 获取通过握手传递的参数
        String token = (String) session.getAttributes().get("token");
        log.info("token:{}",token);
        // 给客户端发送回消息
        session.sendMessage(new TextMessage("Hello, client! You said: " + incomingMessage));
    }
}
